/****** Object:  Table [dbo].[Blogs]    Script Date: 01/21/2008 23:37:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Blogs](
           [BlogID] [int] IDENTITY(0,1) NOT NULL,
           [BlogCode] [nvarchar](50) NOT NULL CONSTRAINT [DF_Blogs_BlogCode]  DEFAULT (N''''),
           [Title] [nvarchar](250) NOT NULL CONSTRAINT [DF_Blogs_BlogName]  DEFAULT (''),
           [SubTitle] [nvarchar](250) NOT NULL CONSTRAINT [DF_Blogs_SubTitle]  DEFAULT (''),
           [Link] [nvarchar](250) NOT NULL CONSTRAINT [DF_Blogs_Link]  DEFAULT (''),
 CONSTRAINT [PK_Blogs] PRIMARY KEY CLUSTERED 
(
           [BlogID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PostCategories]    Script Date: 01/21/2008 23:37:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [PostCategories](
           [PostID] [int] NOT NULL CONSTRAINT [DF_PostCategories_PostID]  DEFAULT ((0)),
           [CategoryID] [int] NOT NULL CONSTRAINT [DF_PostCategories_CategoryID]  DEFAULT ((0)),
 CONSTRAINT [PK_PostCategories] PRIMARY KEY CLUSTERED 
(
           [PostID] ASC,
           [CategoryID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PostTags]    Script Date: 01/21/2008 23:37:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [PostTags](
           [PostID] [int] NOT NULL CONSTRAINT [DF_PostTags_PostID]  DEFAULT ((0)),
           [TagID] [int] NOT NULL CONSTRAINT [DF_PostTags_TagID]  DEFAULT ((0)),
 CONSTRAINT [PK_PostTags] PRIMARY KEY CLUSTERED 
(
           [PostID] ASC,
           [TagID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Posts]    Script Date: 01/21/2008 23:37:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Posts](
           [PostID] [int] IDENTITY(0,1) NOT NULL,
           [BlogID] [int] NOT NULL CONSTRAINT [DF_Posts_BlogID]  DEFAULT ((0)),
           [Title] [nvarchar](250) NOT NULL CONSTRAINT [DF_Posts_Title]  DEFAULT (''),
           [Summary] [nvarchar](250) NOT NULL CONSTRAINT [DF_Posts_Summary]  DEFAULT (''),
           [Body] [nvarchar](max) NOT NULL CONSTRAINT [DF_Posts_Body_1]  DEFAULT (''),
           [AuthorUserID] [int] NOT NULL CONSTRAINT [DF_Posts_AuthorUserID]  DEFAULT ((0)),
           [PublishDate] [datetime] NULL,
           [IsPublished] [bit] NOT NULL CONSTRAINT [DF_Posts_IsPublished]  DEFAULT ((0)),
           [ModifiedDate] [datetime] NULL,
           [CreatedDate] [datetime] NULL,
           [CreatedByUserID] [int] NOT NULL CONSTRAINT [DF_Posts_CreatedByUserID]  DEFAULT ((0)),
           [UpdatedDate] [datetime] NULL,
           [UpdatedByUserID] [int] NOT NULL CONSTRAINT [DF_Posts_UpdatedByUserID]  DEFAULT ((0)),
 CONSTRAINT [PK_Posts] PRIMARY KEY CLUSTERED 
(
           [PostID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Categories]    Script Date: 01/21/2008 23:37:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Categories](
           [CategoryID] [int] IDENTITY(0,1) NOT NULL,
           [ParentCategoryID] [int] NOT NULL CONSTRAINT [DF_Categories_ParentCategoryID]  DEFAULT ((0)),
           [BlogID] [int] NOT NULL CONSTRAINT [DF_Categories_BlogID]  DEFAULT ((0)),
           [Name] [nvarchar](250) NOT NULL CONSTRAINT [DF_Categories_Name]  DEFAULT (''),
 CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED 
(
           [CategoryID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Tags]    Script Date: 01/21/2008 23:37:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Tags](
           [TagID] [int] IDENTITY(0,1) NOT NULL,
           [BlogID] [int] NOT NULL CONSTRAINT [DF_Tags_BlogID]  DEFAULT ((0)),
           [Name] [nvarchar](250) NOT NULL CONSTRAINT [DF_Tags_Name]  DEFAULT (''),
 CONSTRAINT [PK_Tags] PRIMARY KEY CLUSTERED 
(
           [TagID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Users]    Script Date: 01/21/2008 23:37:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Users](
           [UserID] [int] IDENTITY(0,1) NOT NULL,
           [UserName] [nvarchar](250) NOT NULL CONSTRAINT [DF_Users_UserName]  DEFAULT (''),
           [BlogID] [int] NOT NULL CONSTRAINT [DF_Users_BlogID]  DEFAULT ((0)),
           [Email] [nvarchar](250) NOT NULL CONSTRAINT [DF_Users_Email]  DEFAULT (''),
           [Password] [nvarchar](50) NOT NULL CONSTRAINT [DF_Users_Password]  DEFAULT (''),
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
           [UserID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Comments]    Script Date: 01/21/2008 23:37:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Comments](
           [CommentID] [int] IDENTITY(0,1) NOT NULL,
           [PostID] [int] NOT NULL CONSTRAINT [DF_Comments_PostID]  DEFAULT ((0)),
           [Title] [nvarchar](250) NOT NULL CONSTRAINT [DF_Comments_Title]  DEFAULT (''),
           [Body] [nvarchar](max) NOT NULL CONSTRAINT [DF_Comments_Body]  DEFAULT (''),
 CONSTRAINT [PK_Comments] PRIMARY KEY CLUSTERED 
(
           [CommentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  ForeignKey [FK_Categories_Blogs]    Script Date: 01/21/2008 23:37:18 ******/
ALTER TABLE [Categories]  WITH CHECK ADD  CONSTRAINT [FK_Categories_Blogs] FOREIGN KEY([BlogID])
REFERENCES [Blogs] ([BlogID])
GO
ALTER TABLE [Categories] CHECK CONSTRAINT [FK_Categories_Blogs]
GO
/****** Object:  ForeignKey [FK_Categories_Categories_Parent]    Script Date: 01/21/2008 23:37:18 ******/
ALTER TABLE [Categories]  WITH CHECK ADD  CONSTRAINT [FK_Categories_Categories_Parent] FOREIGN KEY([ParentCategoryID])
REFERENCES [Categories] ([CategoryID])
GO
ALTER TABLE [Categories] CHECK CONSTRAINT [FK_Categories_Categories_Parent]
GO
/****** Object:  ForeignKey [FK_Comments_Posts]    Script Date: 01/21/2008 23:37:20 ******/
ALTER TABLE [Comments]  WITH CHECK ADD  CONSTRAINT [FK_Comments_Posts] FOREIGN KEY([PostID])
REFERENCES [Posts] ([PostID])
GO
ALTER TABLE [Comments] CHECK CONSTRAINT [FK_Comments_Posts]
GO
/****** Object:  ForeignKey [FK_PostCategories_Categories]    Script Date: 01/21/2008 23:37:21 ******/
ALTER TABLE [PostCategories]  WITH CHECK ADD  CONSTRAINT [FK_PostCategories_Categories] FOREIGN KEY([CategoryID])
REFERENCES [Categories] ([CategoryID])
GO
ALTER TABLE [PostCategories] CHECK CONSTRAINT [FK_PostCategories_Categories]
GO
/****** Object:  ForeignKey [FK_PostCategories_Posts]    Script Date: 01/21/2008 23:37:22 ******/
ALTER TABLE [PostCategories]  WITH CHECK ADD  CONSTRAINT [FK_PostCategories_Posts] FOREIGN KEY([PostID])
REFERENCES [Posts] ([PostID])
GO
ALTER TABLE [PostCategories] CHECK CONSTRAINT [FK_PostCategories_Posts]
GO
/****** Object:  ForeignKey [FK_Posts_Blogs]    Script Date: 01/21/2008 23:37:28 ******/
ALTER TABLE [Posts]  WITH CHECK ADD  CONSTRAINT [FK_Posts_Blogs] FOREIGN KEY([BlogID])
REFERENCES [Blogs] ([BlogID])
GO
ALTER TABLE [Posts] CHECK CONSTRAINT [FK_Posts_Blogs]
GO
/****** Object:  ForeignKey [FK_Posts_Users_Author]    Script Date: 01/21/2008 23:37:28 ******/
ALTER TABLE [Posts]  WITH CHECK ADD  CONSTRAINT [FK_Posts_Users_Author] FOREIGN KEY([AuthorUserID])
REFERENCES [Users] ([UserID])
GO
ALTER TABLE [Posts] CHECK CONSTRAINT [FK_Posts_Users_Author]
GO
/****** Object:  ForeignKey [FK_Posts_Users_Created]    Script Date: 01/21/2008 23:37:28 ******/
ALTER TABLE [Posts]  WITH CHECK ADD  CONSTRAINT [FK_Posts_Users_Created] FOREIGN KEY([CreatedByUserID])
REFERENCES [Users] ([UserID])
GO
ALTER TABLE [Posts] CHECK CONSTRAINT [FK_Posts_Users_Created]
GO
/****** Object:  ForeignKey [FK_Posts_Users_Updated]    Script Date: 01/21/2008 23:37:29 ******/
ALTER TABLE [Posts]  WITH CHECK ADD  CONSTRAINT [FK_Posts_Users_Updated] FOREIGN KEY([UpdatedByUserID])
REFERENCES [Users] ([UserID])
GO
ALTER TABLE [Posts] CHECK CONSTRAINT [FK_Posts_Users_Updated]
GO
/****** Object:  ForeignKey [FK_PostTags_Posts]    Script Date: 01/21/2008 23:37:30 ******/
ALTER TABLE [PostTags]  WITH CHECK ADD  CONSTRAINT [FK_PostTags_Posts] FOREIGN KEY([PostID])
REFERENCES [Posts] ([PostID])
GO
ALTER TABLE [PostTags] CHECK CONSTRAINT [FK_PostTags_Posts]
GO
/****** Object:  ForeignKey [FK_PostTags_Tags]    Script Date: 01/21/2008 23:37:30 ******/
ALTER TABLE [PostTags]  WITH CHECK ADD  CONSTRAINT [FK_PostTags_Tags] FOREIGN KEY([TagID])
REFERENCES [Tags] ([TagID])
GO
ALTER TABLE [PostTags] CHECK CONSTRAINT [FK_PostTags_Tags]
GO
/****** Object:  ForeignKey [FK_Tags_Blogs]    Script Date: 01/21/2008 23:37:32 ******/
ALTER TABLE [Tags]  WITH CHECK ADD  CONSTRAINT [FK_Tags_Blogs] FOREIGN KEY([BlogID])
REFERENCES [Blogs] ([BlogID])
GO
ALTER TABLE [Tags] CHECK CONSTRAINT [FK_Tags_Blogs]
GO
/****** Object:  ForeignKey [FK_Users_Blogs]    Script Date: 01/21/2008 23:37:35 ******/
ALTER TABLE [Users]  WITH CHECK ADD  CONSTRAINT [FK_Users_Blogs] FOREIGN KEY([BlogID])
REFERENCES [Blogs] ([BlogID])
GO
ALTER TABLE [Users] CHECK CONSTRAINT [FK_Users_Blogs]
GO

